package com.fancy.learncenter.ui.view;

import android.app.Activity;
import android.content.Context;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.PopupWindow;

import com.fancy.learncenter.R;
import com.fancy.learncenter.bean.CartoonUnitBean;
import com.fancy.learncenter.ui.adapter.CartoonUnitAdapter;
import com.fancy.learncenter.ui.callback.AlbumImpl;

import java.util.List;

/**
 * Created by shiweiwei on 2018/1/5.
 */

public class CartoonUnitListPopu extends PopupWindow {

    private View layoutView;
    private List<CartoonUnitBean> list;
    private View rootView;
    private Context mContext;
    private CustomRecycleView recyclerView;
    private CartoonUnitAdapter adapter;


    public void setListener(AlbumImpl listener) {
        this.listener = listener;
    }

    private AlbumImpl listener;
    public CartoonUnitListPopu(Activity mContext, View layoutView, List<CartoonUnitBean> list) {
        super(mContext);
        this.list = list;
        this.layoutView = layoutView;
        this.mContext = mContext;
        initView();
    }


    private void initView(){

        rootView = LayoutInflater.from(mContext).inflate(R.layout.popu_cartoon_unit_list,null);
        recyclerView = (CustomRecycleView) rootView.findViewById(R.id.recyclerView);
        LinearLayoutManager manager = new LinearLayoutManager(mContext);
        manager.setOrientation(LinearLayoutManager.VERTICAL);
        recyclerView.setLayoutManager(manager);
        adapter = new CartoonUnitAdapter(mContext,list);
        recyclerView.setAdapter(adapter);
        adapter.setListener(new AlbumImpl() {
            @Override
            public void onClick(int position) {

                if (listener != null){
                    listener.onClick(position);
                }
            }
        });

        setWidth(ViewGroup.LayoutParams.MATCH_PARENT);
        setHeight(ViewGroup.LayoutParams.MATCH_PARENT);

        rootView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                dismiss();
            }
        });

        setContentView(rootView);

    }

    public void showPopupWindow(){
        showAtLocation(layoutView, Gravity.CENTER, 0, 0);
    }


}
